<?php
/**
 * h5页面接口
 * Created by PhpStorm.
 * User: Earl <guo@seosite.cn>
 * Date: 2017/9/25
 * Time: 下午5:33
 * Updatetime:
 * updater：
 */
namespace Wap\Controller;
header("Access-Control-Allow-Origin: *");
use Think\Controller;

class H5Controller extends Controller {

    public static function short($url) {

        //http://api.t.sina.com.cn/short_url/shorten.json?source=579177356&url_long=http://www.seosite.cn

        $center = 'http://api.t.sina.com.cn/short_url/shorten.json';
        $source = '579177356';
        $get_url = $center.'?source='.$source.'&url_long='.$url;
        $content = curlGet($get_url);

        $j_content =   json_decode($content);

        if (isset($j_content->error_code)){
            return showErrorMsg($j_content->error,10002);
        }

        return $j_content;
    }

    /**
     * @desc 获取短连接
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array
     */
    public function getShortUrl($param)
    {
        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('url');

        $url = $param['url'];

        $center = 'http://api.t.sina.com.cn/short_url/shorten.json';
        $source = '579177356';
        $get_url = $center.'?source='.$source.'&url_long='.$url;
        $content = curlGet($get_url);

        $j_content = json_decode($content);
        if (isset($j_content->error_code)){
            return showErrorMsg($j_content->error,10002);
        }

        $ret_data = array(
            'url_long'  =>  $url,
            'url_short' =>  $j_content[0]->url_short
        );
        return showErrorMsg(L("_OPERATION_SUCCESS_"),0,2,$ret_data);
    }

    /**
     * @desc 分享
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array
     */
    public function share($param)
    {
        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('type,id');

        unset($check);

        $title = '';
        $content = '';
        $headsmall = '';
        $slogan = '';
        $id = $param['id'];
        $type = $param['type'];
        switch ($type){//1 视频，2视频直播，3音频直播，4音频，5报告，6图片，7快讯，8数据，9会议，10专栏，11问答，12问卷

            case 1://视频
                $info = M('video')->where(['id'=>$id])->find();
                $title      = $info['title'];
                $content    = $info['abstract'];
                $headsmall  = $info['headsmall'];
                break;
            case 2://视频直播
                $info = M('direct')->where(['id'=>$id])->find();
                $title      = $info['title'];
                $content    = $info['meeting_subject'];
                $headsmall  = $info['headsmall'];
                break;
            case 3://音频直播
                $info = M('audio')->where(['id'=>$id])->find();
                $title      = $info['title'];
                $content    = $info['meeting_subject'];
                $headsmall  = $info['headsmall'];
                break;
            case 4://音频
                $info = M('mp3')->where(['id'=>$id])->find();
                $title      = $info['title'];
                $content    = $info['abstract'];
                $headsmall  = $info['headsmall'];
                break;
            case 5://报告
                $info = M('report')->where(['id'=>$id])->find();
                $title      = $info['title'];
                $content    = $info['abstract'];
                $headsmall  = $info['headsmall'];
                break;
            case 6://图片
                $info = M('picture')->where(['id'=>$id])->find();
                $title      = $info['title'];
                $y_content    = !empty($info['content'])?unserialize($info['content']):'';
                $content = $y_content[0]['content'];
                $headsmall  = $info['headsmall'];
                break;
            case 7://快讯
                $info = M('news')->where(['id'=>$id])->find();
                $content    = $info['content'];
                break;
            case 8://数据
                $info = M('data')->where(['id'=>$id])->find();
                $title      = $info['title'];
                $content    = '金融市场越复杂，越需要理顺逻辑关系';
                $headsmall  = C('site_logo');
                break;
            case 9://会议
                $info = M('meeting')->where(['id'=>$id])->find();
                $title      = $info['title'];
                $content    = $info['abstract'];
                $headsmall  = $info['headsmall'];
                break;
            case 11://问答
                $info = M('qa')->where(['id'=>$id])->find();
                $title      = '问答 | '.M('user')->where(['id'=>$info['uid']])->getField('nickname');
                $content    = $info['content'];
                $headsmall  = $info['headsmall'];
                $slogan     = '没有调研就没有发言权';
                break;
            case 12://问卷
                $info = M('question')->where(['id'=>$id])->find();
                $title      = $info['title'];
                $content    = $info['abstract'];
                $headsmall  = $info['headsmall'];
                $slogan = '听君一席话，胜读十年书。';
                break;
        }

        $ret_data = array(
            'title'     =>  $title,
            'content'   =>  $content,
            'headsmall' =>  $headsmall,
            'slogan'    =>  $slogan,
            'id'        =>  $id,
            'type'      =>  $type
        );
        return showErrorMsg(L('_OPERATION_SUCCESS_'),0,2,$ret_data);
    }

}